package cn.pdx.elec.web.action;


import cn.pdx.elec.container.ServiceProvider;
import cn.pdx.elec.domain.ElecText;
import cn.pdx.elec.service.ElecTextService;
import cn.pdx.elec.util.StringHelper;
import cn.pdx.elec.web.form.ElecTextForm;
import com.opensymphony.xwork2.ModelDriven;

/**
 * implements ModelDriven<T>实现这个接口，泛型
 * ModelDriven<ElecTextForm>表示这个表单对象
 * @author 彭定旭
 *
 */
@SuppressWarnings("serial")
public class ElecTextAction extends BaseAction implements  ModelDriven<ElecTextForm>{
    
	/**
	 * 创建一个表单对象，对应页面的属性的对象
	 */
	private ElecTextForm elecTextForm=new ElecTextForm();
	
	/**
	 * 使用方法调用ElecTextService.SERVICE_NAME 接口
	 */
	private ElecTextService elecTextService=(ElecTextService) ServiceProvider.getService(ElecTextService.SERVICE_NAME);
	
	
	public ElecTextForm getModel() {
		
		return elecTextForm;
	}
    
	public String save() throws Exception
	{ 
		
		//System.out.println(elecTextForm.getTextName());//成功ok
		//这样用request输出也可以
		//System.out.println(request.getParameter("textName"));
		
		/**
		 * 将vo对象转换成po对象
		 */
		
		//实例化po对象
		ElecText elecText=new ElecText();
		elecText.setTextName(elecTextForm.getTextName());
		elecText.setTextDate(StringHelper.stringConvertDate(elecTextForm.getTextDate()));
		elecText.setTextRemark(elecTextForm.getTextRemark());
		
		elecTextService.saveElecText(elecText);
		
		return "save";
		
	}

	
}
